package ru.dc.object;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;

/**
 * <pre>
 * User: Penkov Vladimir
 * Date: 08.10.2010
 * Time: 15:46:24
 * </pre>
 */
public class ServerInfo implements Serializable {

    private PropertyChangeSupport pcs = new PropertyChangeSupport(this);

    private String address;
    private int port = 411;
    private String encoding = "windows-1251";
    private String nick;
    private boolean active;

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        Object old = this.address;
        this.address = address;
        pcs.firePropertyChange("address", old, address);
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        int old = this.port;
        this.port = port;
        pcs.firePropertyChange("port", old, port);
    }

    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        Object old = this.encoding;
        this.encoding = encoding;
        pcs.firePropertyChange("encoding", old, encoding);
    }

    public String getNick() {
        return nick;
    }

    public void setNick(String nick) {
        Object old = this.nick;
        this.nick = nick;
        pcs.firePropertyChange("nick", old, nick);
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        boolean old = this.active;
        this.active = active;
        pcs.firePropertyChange("port", old, this.active);
    }

    @Override
    public String toString() {
        return "ServerInfo{" +
                "address='" + address + '\'' +
                ", port=" + port +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ServerInfo that = (ServerInfo) o;

        if (port != that.port) return false;
        if (address != null ? !address.equals(that.address) : that.address != null) return false;
        if (encoding != null ? !encoding.equals(that.encoding) : that.encoding != null) return false;
        if (nick != null ? !nick.equals(that.nick) : that.nick != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = address != null ? address.hashCode() : 0;
        result = 31 * result + port;
        result = 31 * result + (encoding != null ? encoding.hashCode() : 0);
        result = 31 * result + (nick != null ? nick.hashCode() : 0);
        return result;
    }

    public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
        pcs.addPropertyChangeListener(propertyChangeListener);
    }

    public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener) {
        pcs.removePropertyChangeListener(propertyChangeListener);
    }
}
